if (!nshc_bad_version( nshc_parms, nshc_calls, NSHC_VERSION )) {
// otherwise, handle requests from the application
switch (nshc_parms->action) {
case nsh_start:
nshc_calls->NSH_printf("Hello World\r");
break;
case nsh_continue:
case nsh_idle:
case nsh_stop:
break;
}
// tell the application we are done
nshc_parms->action = nsh_idle;
nshc_parms->result = NSHC_NO_ERR;
}
}
The include file:
#include "nshc.h"
defines the interface between the nShell application and its external commands. The file contains the prototype for the command “main” and the definitions for the “nshc_parms” and “nshc_calls” parameter blocks which are used in that call:
if (!nshc_bad_version(nshc_parms, nshc_calls, NSHC_VERSION))
is to a standard routine in the file "nshc_utl.c". This routine confirms that the same versions of nshc.h were used to build the nShell application and this command. If there is a version mismatch, nshc_bad_version sets the command action to nsh_idle and the command result to NSHC_ERR_VERSION.
The switch statement is used to interpret the “action” message from the application:
switch (nshc_parms->action) {
case nsh_start:
nshc_calls->NSH_printf("Hello World\r");
break;
case nsh_continue:
case nsh_idle:
case nsh_stop:
break;
}
Whenever this command is sent an nsh_start, it prints a “Hello World” message. When it is sent an nsh_continue, nsh_idle or nsh_stop message, it takes no action.
The printf call is made through the nshc_calls block:
nshc_calls->NSH_printf("Hello World\r");
This internal version of printf is compatible with nShell I/O redirection.
In any case, the command considers itself done, and sets the action to nsh_idle and the result to NSHC_NO_ERR (ie. zero):
nshc_parms->action = nsh_idle;
nshc_parms->result = NSHC_NO_ERR;
If this were not done, the application would call the command repeatedly waiting for the action became nsh_idle, resulting in an endless loop.